//
//  UIDevice.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/13.
//

import UIKit
import Foundation

extension String {
	func ht_toDict() -> [String: Any] {
		var var_result: [String : Any] = [:]
		guard !self.isEmpty else { return var_result }
		guard let var_dataSelf = self.data(using: .utf8) else {
			return var_result
		}
		if let var_dic = try? JSONSerialization.jsonObject(with: var_dataSelf, options: .mutableContainers) as? [String : Any] {
      var_result = var_dic
		}
		return var_result
	}
	
	// 是否在范围内 例rawString="1-100"
	func ht_inRange(var_rawString: String) ->Bool {
		let var_allStrings = var_rawString.components(separatedBy: "-")
		if var_allStrings.count != 2 {
			return false
		}
		let var_petty = Int(var_allStrings[0])
		let var_big = Int(var_allStrings[1])
		if Int(self) ?? 0 >= var_petty! && Int(self) ?? 0 <= var_big! {
			return true
		} else {
			return false
		}
	}
	
	// ","转成"/"
	func ht_infoDetail() -> String {
		return self.replacingOccurrences(of: ",", with: " / ", options: .literal, range: nil)
	}
	
	// 格式00:00:00 转成秒
	func ht_time2second() -> Int {
		let var_allStrings = self.components(separatedBy: ":")
		if var_allStrings.count == 0 {
			return 0
		} else if var_allStrings.count == 2 {
			return Int(var_allStrings[0])! * 60 + Int(var_allStrings[1])!
		} else if var_allStrings.count == 3 {
			return Int(var_allStrings[0])! * 3600 + Int(var_allStrings[1])! * 60 + Int(var_allStrings[2])!
		} else {
			return 0
		}
	}
}
